### 浏览器

浏览器版本api 在node版本上扩充了一些浏览器才可以使用的api

#### aui.screenWidth [> 1.6.x]

```javascript
let getScreenWidth = function() {
  return screen.width > 0 ? screen.width : 0;
}
```

#### aui.isPhoneSize [> 1.6.x]

```javascript
let isPhoneSize = function(maxWidth = 768) {
    return getScreenWidth() < maxWidth && detectMediaMacthes('(max-device-width: 769px)');
}
```

各种设备media query
https://css-tricks.com/snippets/css/media-queries-for-standard-devices/

example
```javascript
var isIPHONEXSize = aui.detectMediaMatches("@media only screen and (min-device-width: 375px) and (max-device-width: 812px) and (-webkit-min-device-pixel-ratio: 3)");
```

#### aui.isPhoneWeixin [> 1.7.x]

判断是否在手机微信中

```javascript
export let isPhoneWeixin = function() {
    return isPhoneSize() && this.browser.isLikeWeixin();
}
```

#### aui.requestPermission [stage 1]

```javascript
function CreatNotification() {
const NotificationInstance = Notification || window.Notification;
    const n = new NotificationInstance('XX网站消息通知', {
        body: '你的朋友有新状态啦，快去围观吧！',
        tag: '2ue',
        icon: 'https://2ue.github.io/images/common/avatar.png',
        data: {
            url: 'https://2ue.github.io'
        }
    });
    n.onshow = function () {
        console.log('通知显示了！');
    }
    n.onclick = function (e) {
        //可以直接通过实例的方式获取data内自定义的数据
        //也可以通过访问回调参数e来获取data的数据
        window.open(n.data.url, '_blank');
        n.close();
    }
    n.onclose = function () {
        console.log('你墙壁了我！！！');
    }
    n.onerror = function (err) {
        console.log('出错了，小伙子在检查一下吧');
        throw err;
    }
    setTimeout(() => {
        n.close();
    }, 7000);
}

const NotificationInstance = Notification || window.Notification;

function setPermission(onGranted, onRejected) {
    //请求获取通知权限
    NotificationInstance.requestPermission(function (PERMISSION) {
        if (PERMISSION === 'granted') {
            onGranted();
        } else {
            // console.log('用户无情残忍的拒绝了你!!!');
            onRejected();
        }
    });
}

function checkNotificationPermission() {
  return new Promise(function(resolve, reject) {
      if (!!NotificationInstance) {
        const permissionNow = NotificationInstance.permission;
        if (permissionNow === 'granted') {
            //允许通知
            resolve();
        } else if (permissionNow === 'denied') {
            // console.log('用户拒绝了你!!!');
            reject(new aui.PemissionRejectError());
        } else {
            setPermission(function() {
                resolve();
            }, function() {
              reject(new aui.PemissionRejectError());
            });
        }
      }
  });
}

export function requestPermission(name) {
  if (name == "browser.notification") {
     return checkNotificationPermission(); 
  }
}

// const NotificationInstance = Notification || window.Notification;
// if (!!NotificationInstance) {
//     const permissionNow = NotificationInstance.permission;
//     if (permissionNow === 'granted') {//允许通知
//         CreatNotification();
//     } else if (permissionNow === 'denied') {
//         console.log('用户拒绝了你!!!');
//     } else {
//         setPermission();
//     }
//     function setPermission() {
//         //请求获取通知权限
//         NotificationInstance.requestPermission(function (PERMISSION) {
//             if (PERMISSION === 'granted') {
//                 CreatNotification();
//             } else {
//                 console.log('用户无情残忍的拒绝了你!!!');
//             }
//         });
//     }
// }
``` 

#### aui.setStorageSync [> 1.5.0] <depretched></depretched>

没有key的话会新创建一个storage

example

```javascript
try {
    aui.setStorageSync('key', 'data', {
        expire: new Date(1516598076171)
    })
} catch (e) {
    console.error(e);
}
```

#### aui.getStorageSync [> 1.5.0] <depretched></depretched>

如果没有就返回null

example
```javascript
try {
    let v = aui.getStorageSync('key', 'data');
    if (v === null) {
        // 没有数据的情况
    } else {
        
    }
} catch (e) {
    console.error(e);
}
```

#### aui.removeStorageSync [> 1.5.0] <depretched></depretched>

删除storage中某个key的值

example
```javascript
aui.removeStorageSync('key');
```

#### aui.updateStorageSync [> 1.5.0] <depretched></depretched>

更新某个值 但如果不存在或已过期不会新建key

成功返回true 失败返回false

example
```javascript
aui.updateStorageSync('key', 'new data');
```

#### aui.clearStorageSync [> 1.5.0] <depretched></depretched>

清空storage

#### aui.touchStorageSync [stage1]

设置某个key的option

成功返回true 失败返回false